package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     */
    @ApiOperation("查询所有护理计划")
    @GetMapping
    public ResponseResult list(){
        List<NursingPlan> list = nursingPlanService.findAll();
        return ResponseResult.success(list);
    }

    /**
     * 新增护理计划
     */
    @ApiOperation("新增护理计划")
    @PostMapping
    public ResponseResult add(@ApiParam(value = "护理计划数据传输对象", required = true)
            @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     *条件分页查询
     */
    @ApiOperation("条件分页查询")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> selectPage(@ApiParam(value = "护理计划名称") String name,
                                                                  @ApiParam(value = "当前页") @RequestParam(defaultValue = "1")Integer pageNum,
                                                                  @ApiParam(value = "每页显示记录数")@RequestParam(defaultValue = "10") Integer pageSize,
                                                                  @ApiParam(value = "状态")Integer status){
        PageResponse<NursingPlanVo> pageResponse = nursingPlanService.getByPage(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    /**
     * 根据id查询回显
     */
    @ApiOperation("根据id查询护理计划")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById(
            @PathVariable("id") Integer id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getInfo(id);
        return success(nursingPlanVo);
    }
    /**
     * 修改护理计划
     */
    @ApiOperation("修改护理计划")
    @PutMapping("/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto,@PathVariable Integer id){
        nursingPlanService.update(nursingPlanDto,id);
        return success();
    }
    /**
     * 删除护理计划
     */
    @ApiOperation("删除护理计划")
    @DeleteMapping("{id}")
    public ResponseResult delete(@PathVariable("id") Integer id){
        nursingPlanService.deleteById(id);
        return success();
    }

    /**
     * 启用和禁用
     */
    @ApiOperation("启用和禁用")
    @PutMapping("{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable("id") Integer id,@PathVariable("status") Integer status){
        nursingPlanService.updateStatus(id,status);
        return success();
    }

}

